<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="/static/css/font.css">
        <link rel="stylesheet" href="/static/css/xadmin.css">
        <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/static/js/xadmin.js"></script>
    </head>
    <body>
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <script>

        </script>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-header">
                            <button class="layui-btn" onclick="xadmin.open('添加权限节点','rule-add.jsp',600,400)"><i class="layui-icon"></i>添加权限节点</button>
<%--
                            <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
--%>
                        </div>
                        <div class="layui-card-body ">
                            <table id="test" class="layui-hide" lay-filter="test"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div> 
    </body>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs"  lay-event="edit" onclick="xadmin.open('修改','rule-edit.jsp',600,400)">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>

    <script>

        layui.use('table', function() {
            var table = layui.table;

            table.render({
                elem: '#test',
                height: 480,
                url: '/delect/listuser',
                page: true, //开启分页
                limit:10,
                limits:[10,20,30],
                cols: [[ //表头
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'pId', title: 'ID', sort: true, fixed: 'left', width: 80},
                    {field: 'pName', title: '权限名称', sort: true, fixed: 'left', width: 120},
                    {field: 'pUrl', title: 'URL路径', sort: true, fixed: 'left', width: 120},
                    {field: 'operator', title: '操作', toolbar: '#barDemo', width: 180}

                ]]
            });
            //头工具栏事件
            table.on('toolbar(test)', function(obj){
                var checkStatus = table.checkStatus(obj.config.id);
                switch(obj.event){
                    case 'getCheckData':
                        var data = checkStatus.data;
                        layer.alert(JSON.stringify(data));
                        break;
                    case 'getCheckLength':
                        var data = checkStatus.data;
                        layer.msg('选中了：'+ data.length + ' 个');
                        break;
                    case 'isAll':
                        layer.msg(checkStatus.isAll ? '全选': '未全选');
                        break;

                    //自定义头工具栏右侧图标 - 提示
                    case 'LAYTABLE_TIPS':
                        layer.alert('这是工具栏右侧自定义的一个图标按钮');
                        break;
                };
            });

            //监听行工具事件
            table.on('tool(test)', function(obj){
                var data = obj.data;
                //console.log(obj)
                if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        var pid = data.pId;
                        $.ajax("/delect/PermissionController", {
                            type: "POST",
                            data: {

                                pid:pid

                            },
                            dataType: "json",	// 设置响应类型，jquery会自动将响应结果做对应的类型转换
                            success: function (data, textStatus, jqXhr) {
                                console.log(data);
                                console.log('data的类型： ' + (typeof data));
                                console.log(textStatus);
                            }
                        });
                        obj.del();
                        layer.close(index);
                    });
                }
            });


        });

    </script>


    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    </script>
</html>